/*
* $Id: STreeItem.cpp 130 2010-08-06 15:19:16Z volok-aleksej@yandex.ru $
*
* Copyright 2010 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "STreeItem.h"

CSTreeItem::CSTreeItem(int nId, const std::tstring& strName)
: m_nId(nId), m_strName(strName), m_bSel(false), 
m_point(0, 0), m_size(SIZE_STREE_ITEM_X, SIZE_STREE_ITEM_Y){}
CSTreeItem::~CSTreeItem(){}

void CSTreeItem::SetPos(CPoint pos){
	m_point = pos;
}

void CSTreeItem::SetSel(bool bSel){
	m_bSel = bSel;
}

bool CSTreeItem::IsSel(){
	return m_bSel;
}

void CSTreeItem::Paint(CDC* dc){
	CBrush brush;
	CPen pen(PS_SOLID, 1, RGB(0, 0, 0));
	if(m_bSel)
		brush.CreateSolidBrush(CCommonFunction::GetBeeColor());
	else
		brush.CreateSolidBrush(GetSysColor(COLOR_3DFACE));
	HGDIOBJ brushOld = dc->SelectObject(brush.m_hObject);
	HGDIOBJ penOld = dc->SelectObject(pen.m_hObject);
	dc->Rectangle(CRect(m_point, m_size));
	dc->SetBkMode(TRANSPARENT);
	CRect rect(m_point, m_size);
	dc->DrawText(m_strName.c_str(), rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT);
	rect.SetRect(m_point.x + rect.Size().cx/2 - 5, m_point.y + rect.Size().cy/2,
		m_point.x + m_size.cx - rect.Size().cx/2 + 5, m_point.y + m_size.cy - rect.Size().cy/2);
	dc->DrawText(m_strName.c_str(), rect, DT_CENTER | DT_WORDBREAK);
	dc->SelectObject(penOld);
	dc->SelectObject(brushOld);
	brush.DeleteObject();
	pen.DeleteObject();
}

CRect CSTreeItem::GetRect(){
	return CRect(m_point, m_size);
}

int CSTreeItem::GetId(){
	return m_nId;
}
